<template>
  <div class="zn-wrapper">

    <!--查询-->
    <div class="zn-search-header">
      <div class="search">
        <div v-for="item in searchData" :key="item.key" class="searchItem">
          <label>{{$t(`${name}.search.${item.key}`)}}：</label>
          <el-input size="small" :placeholder="$t('common.search')" v-model="search[item.key]" v-if="item.type === 'input'"></el-input>
          <el-select size="small" :placeholder="$t('common.search')" v-model="search[item.key]" v-if="item.type === 'select'">
            <el-option
              v-for="i in item.options"
              :key="i.value"
              :value="i.value"
              :label="i.label">
            </el-option>
          </el-select>
          <el-date-picker
            v-if="item.type === 'dateTime'"
            v-model="search[item.key]"
            type="datetime"
            size="small"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择日期时间">
          </el-date-picker>
        </div>
        <el-button size="mini" class="searchBtn" type="primary" icon="el-icon-search" @click="getList()"></el-button>
      </div>
    </div>
    <!--添加-->
    <!--<div class="zn-op-header">-->
      <!--<el-button size="mini" type='primary' icon="el-icon-plus" @click="addClick">发货</el-button>-->
    <!--</div>-->
    <!--<div class="zn-select-up">-->
      <!--<el-tooltip class="item" effect="dark" :content="$t('common.delAll')" placement="top">-->
        <!--<el-button icon="el-icon-delete" size="mini" @click="delAll"></el-button>-->
      <!--</el-tooltip>-->
    <!--</div>-->
    <!--列表-->
    <div class="zn-main">
      <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" v-if="tableHeaderData.hasSelection">
        </el-table-column>
        <el-table-column v-for="header in tableHeaderData.data" :width="header.width" :key="header.prop" :label="$t(`${name}.tableHead.${header.prop}`)" :prop="header.prop">
          <template slot-scope="scoped">
            <div v-if="header.type === 'img'">
              <img :src="scoped.row[header.prop]">
            </div>
            <div v-else-if="header.type === 'link'">
              <a :href="scoped.row[header.prop]">{{scoped.row[header.prop]}}</a>
            </div>
            <div v-else>
              {{scoped.row[header.prop]}}
            </div>
          </template>
        </el-table-column>
        <el-table-column fixed="right" :label="$t('common.operate')" width="70">
          <template slot-scope="scoped">
            <div class="operate">
              <el-tooltip class="item" effect="dark" content="发货" placement="top">
                <el-button icon="el-icon-s-promotion" size="mini" @click="addClick(scoped.row)"></el-button>
              </el-tooltip>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!--<div class="zn-select-down">-->
        <!--<el-tooltip class="item" effect="dark" :content="$t('common.delAll')" placement="top">-->
          <!--<el-button icon="el-icon-delete" size="mini" @click="delAll"></el-button>-->
        <!--</el-tooltip>-->
      <!--</div>-->
      <div class="zn-table-foot clearfix">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="page.pageSize"
          :page-sizes="[10, 50, 100, 200]"
          layout="sizes, total, prev, pager, next"
          :total="page.total">
        </el-pagination>
      </div>
    </div>

    <!-- 弹出新增框 -->
    <el-dialog custom-class="outDetail" title="出库发货详情" :visible.sync="dialogVisible">
      <div :is="children" @close="closeDialog" :package="package"></div>
    </el-dialog>

  </div>
</template>

<script>
  import * as config from "./data";
  import local from './local';
  import api from "@/api/orderDeliverItem.service.js";
  import deiverDetail from './component/deliverDetail.vue'

  export default {
    data() {
      return {
        name: null,
        search: {},
        searchData: [],
        tableData: [],
        tableHeaderData: {},
        children: 'deiverDetail',
        dialogVisible: false, //是否显示添加模态框
        addObj: {}, //当前添加对象
        key: "", //搜索关键字
        currentPage: 1,
        page: {
          pageNo: 1,
          pageSize: 10,
          total: null
        },
        selectAll: null,
        package: null
      };
    },
    components: {
      deiverDetail
    },
    created() {
      this.$i18n.mergeLocaleMessage('en',local.en)
      this.$i18n.mergeLocaleMessage('zh',local.zh)
      this.$i18n.mergeLocaleMessage('ko',local.ko)
      Object.keys(config).map(res => {
        this[res] = config[res]
      })
      this.getList()
    },
    methods: {
      getList() {
        // 调接口拿数据
        console.log(this.search);
        this.search.pageNo = this.page.pageNo
        this.search.pageSize = this.page.pageSize
        api.list(this.search).then(res => {
          this.tableData = res.values
          this.page.total = res.total
        })
      },
      handleSelectionChange(select) {
        this.selectAll = select
      },
//      批量删除
      delAll() {
        if (this.selectAll && this.selectAll.length > 0) {
          this.selectAll.map(res => {
            this.delObj += `${res.id},`
          })
          this.delObj = this.delObj.slice(0, this.delObj.length - 1)
          this.deleteClick(this.delObj)
        } else {
          this.$message({
            message: this.$t('common.delAllTip'),
            type: 'warning'
          });
        }
      },
      // 添加click
      addClick(row) {
        this.dialogVisible = true;
        this.package = row
      },
      handleCurrentChange(pageNo) {
        this.page.pageNo = pageNo
        this.getList()
      },
      handleSizeChange(pageSize) {
        this.page.pageSize = pageSize
        this.getList()
      },
      closeDialog(flag) {
        this.dialogVisible = false
        if (flag) {
          this.getList()
        }
      }
    }
  };
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .zn-op-header {
    margin-bottom:16px;
  }
  .good-detail {
    position: relative;
    padding-left: 80px;
    min-height: 80px;
  }
  .good-detail .good-pic {
    position: absolute;
    left: 0;
    top: 0;
  }
  .good-detail .good-pic img {
    height: 80px;
    width: 80px;
    padding: 1px;
    border: 1px solid #efefef;
  }
  .good-detail .good-content {
    width: 260px;
    padding: 10px;
  }
  .input-with-select {
    width: 300px;
  }
  .zn-search-header {
    display: flex;
    justify-content: space-between;
    border: 1px solid #ddd;
    padding-top: 10px;
    margin-bottom:10px;
  }
  .search {
    display: flex;
    flex-wrap: wrap;
  }
  .searchItem {
    margin-right:20px;
    margin-bottom:10px;
    width: 300px;
    display: flex;
    align-items: center;
    label {
      flex: 1;
      text-align: right;
    }
  }
  .searchItem {
    .el-select {
      width: 200px!important;
    }
    .el-input {
      width: 200px!important;
    }
  }
  .searchBtn {
    height: 32px;
  }
  .operate {
    display: flex;
  }
  .zn-select-up {
    margin-bottom:16px;
  }
  .zn-select-down {
    margin-top:16px;
  }
  .zn-main {
    img {
      width: 100px;
      height: 100px;
    }
  }


</style>

<style lang="scss">
  .zn-main .el-table__header-wrapper .cell {
    font-weight: normal;
    color: #000;
  }
  .zn-main th,td {
    text-align: center!important;
  }
  .outDetail .el-dialog__body {
    height: 600px;
    overflow-y: scroll;
  }
  .outDetail .el-table__body-wrapper::-webkit-scrollbar {
    display: none;
  }
</style>


